<!-- Rebuild -->
<template>
  <div class="rebuild">
    <div class="rebuild-head-left">
      <span>考试科目</span>
      <select v-model="selected">
        <option value="请选择对应考试" selected>--请选择对应考试--</option>
        <option value="大学语文">2019-2020学年第2学期大学语文</option>
        <option value="大学数学">2019-2020学年第2学期大学数学</option>
        <option value="大学英语">2019-2020学年第2学期大学英语</option>
      </select>
    </div>
    <div class="rebuild-head-mid">
      <span>不及格分数小于</span>
      <input type="text" v-model="LessThan" />
    </div>
    <el-row class="rebuild-btn">
      <el-button type="primary" @click="Need">生成重修名单</el-button>
    </el-row>
    <div class="rebuild-main">
      <el-container style="height: 420px; border: 1px solid #ee">
        <el-container>
          <el-main>
            <el-table :data="tableData1" @selection-change="handleSelectionChange">
              <el-table-column width="50" type="selection">
              </el-table-column>
              <el-table-column
                type="index"
                label="序号"
                width="60"
              ></el-table-column>
              <el-table-column
                prop="id"
                label="学号"
                width="120"
              ></el-table-column>
              <el-table-column
                prop="name"
                label="姓名"
                width="120"
              ></el-table-column>
              <el-table-column
                prop="grade"
                label="年级"
                width="80"
              ></el-table-column>
              <el-table-column
                prop="class"
                label="班级"
                width="80"
              ></el-table-column>
              <el-table-column
                prop="subjects"
                label="考试科目"
                width="120"
              ></el-table-column>
              <el-table-column
                prop="results"
                label="成绩"
                width="200"
              ></el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    @click="handleEdit(scope.$index, scope.row)"
                    >编辑</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-main>
        </el-container>
      </el-container>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  computed: {
    tableData1: function () {
      if(this.state===false){
        if (this.selected === "请选择对应考试") {
        if (this.LessThan > 0) {
          return this.tableData.filter((v) => {
            return v.results < this.LessThan;
          });
        }
        return this.tableData;
      } else if (this.selected === "大学语文") {
        if (this.LessThan > 0) {
          return this.tableData.filter((v) => {
            return v.results < this.LessThan && v.subjects === "大学语文";
          });
        }
        return this.tableData.filter((v) => {
          return v.subjects === "大学语文";
        });
      } else if (this.selected === "大学数学") {
        if (this.LessThan > 0) {
          return this.tableData.filter((v) => {
            return v.results < this.LessThan && v.subjects === "大学数学";
          });
        }
        return this.tableData.filter((v) => {
          return v.subjects === "大学数学";
        });
      } else if (this.selected === "大学英语") {
        if (this.LessThan > 0) {
          return this.tableData.filter((v) => {
            return v.results < this.LessThan && v.subjects === "大学英语";
          });
        }
        return this.tableData.filter((v) => {
          return v.subjects === "大学英语";
        });
      } else {
        return this.tableData;
      }
      }else{
        return this.arr
      }
      
    },
  },
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      tableData: [],
      multipleSelection: [],
      selected: "请选择对应考试",
      LessThan: "",
      state:false,
      arr:[]
    };
  },
  //监控data中的数据变化
  watch: {
    // checked:function(newQuestion){
    //   console.log(newQuestion)
    // }
  },
  //方法集合
  methods: {
    // handleEdit(index, row) {
    //     console.log(index, row);
    //   },
    handleSelectionChange(val) {
        this.multipleSelection = val;
      },
    Need:function(){
      this.state=!this.state
      this.arr=this.multipleSelection
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.$http.get("/rebuild").then((res) => {
      this.tableData = res.data;
    });
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style  lang="less">
* {
  margin: 0;
  padding: 0;
}
.rebuild {
  height: 600px;
  padding: 15px 0 0 20px;
  .rebuild-head-left {
    margin-top: 5px;
    float: left;
    width: 300px;
    height: 30px;
    line-height: 30px;
    display: flex;
    justify-content: space-between;
    margin-right: 30px;
    select {
      text-align-last: center;
    }
  }
  .rebuild-head-mid {
    margin-top: 5px;
    float: left;
    width: 300px;
    height: 30px;
    line-height: 30px;
    display: flex;
    justify-content: space-between;
    input {
      font-size: 18px;
      text-indent: 5px;
      width: 180px;
    }
  }
  .rebuild-btn {
    float: right;
  }
  .rebuild-main {
    float: right;
    width: 100%;
    margin-bottom: 10px;
    .el-main {
      padding: 0;
      margin-top: 10px;
    }
  }
}
</style>